package com.chrisandjo.rostra.dao;

import static com.chrisandjo.rostra.dao.RosterDaoTest.ROSTER_ENTITY;
import static com.chrisandjo.rostra.dao.jpa.PersonDaoImpl.PERSON_ENTITY;
import org.springframework.jdbc.core.JdbcTemplate;


public class DatabaseHelper {

    public static void removeAllRosters(JdbcTemplate jdbcTemplate) {
        jdbcTemplate.execute("delete from " +
                ROSTER_ENTITY);
    }

    public static void createRosterRecord(JdbcTemplate jdbcTemplate, String id, String rosterName) {
        jdbcTemplate.execute("insert into " +
                ROSTER_ENTITY +
                " (id, name) values (" +
                id +
                ",'" +
                rosterName +
                "')");
    }

    public static void createPersonRecord(JdbcTemplate jdbcTemplate, String id, String name) {
        jdbcTemplate.execute("insert into " +
                PERSON_ENTITY +
                " (id, name) values (" +
                id +
                ",'" +
                name +
                "')");
    }

    public static void addRosterPersonRecord(JdbcTemplate jdbcTemplate, String rosterId, String personId) {
        jdbcTemplate.execute("insert into " + ROSTER_ENTITY + "_" + PERSON_ENTITY + " values('" +
                rosterId +
                "','" +
                personId +
                "')");
    }

    public static void removeRosterPersonRecords(JdbcTemplate jdbcTemplate) {
        jdbcTemplate.execute("delete from " + ROSTER_ENTITY + "_" + PERSON_ENTITY);
    }

    public static void removeAllPeople(JdbcTemplate jdbcTemplate) {
        jdbcTemplate.execute("delete from " +
                PERSON_ENTITY);
    }
}
